#ifndef IMGCUTTER_H
#define IMGCUTTER_H

#include <QString>
#include <QList>
#include <QMap>

#include <QImage>
#include <QRect>

#include <Qdir>
#include <Qfile>
#include <QFileInfo>
#include <QThread>

class ImgCutter: public QThread{
    Q_OBJECT

public:
    enum RenameStyle{Encoded, Origin, SerialNumber};

    ImgCutter();

    bool setInputDirectory(QString dir);
    bool setOutputDirectory(QString dir);
    QString getImageSample();

    void cut(const QString &file_path);

    void setRectMap(const QMap<QString, QRect> *map);
    void setRenameStyle(RenameStyle style);

    QList<QByteArray> getTerminatedTask();

public slots:
    void start(int from = 0);
    void restart();
    void pause();

signals:
    void error(QString);

    void progressRange(int, int);
    void progressChanged(int);

    void saveRectMap(QString);

protected:
    void run();

    //Rect
    const QMap<QString, QRect> *rect_map;

    QDir input_directory;
    QStringList image_list;
    QDir output_directory;

    RenameStyle rename_style;

private:
    int cur_id;
    QStringList name_filters;
    QFile log_global;
    QFile log_progress;

    bool is_pausing;
};

extern ImgCutter *imgCutter;

#endif // IMGCUTTER_H
